﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class User_MsgContentShow : System.Web.UI.Page {

    private string sendUserLoginName;
    private int mid;
    private string type;

    protected void Page_Load(object sender, EventArgs e) {
        if(!Page.IsPostBack) {
            if(Request["mid"] != null) {
                mid = int.Parse(Request["mid"]);
                type = Request["type"];
                ViewState["mid"] = mid;
            }
            if(mid == 0) {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "", "alert('没有消息显示！')", true);
            } else {
                this.findMsgDataBind(mid);
            }
        }
    }

    //根据消息编号查看消息内容绑定
    protected void findMsgDataBind(int mid) {
        SectionEmpMsgtbService sectionEmpMsgtbService = new SectionEmpMsgtbService();
        SectionEmpMsgtb sectionEmpMsg = sectionEmpMsgtbService.findByMsgId(mid, type);
        sectionEmpMsgtbService.updateMsgState(mid, type);
        this.lblSendDateTime.Text = sectionEmpMsg.SendDateTime.ToString();
        this.lblSendUserName.Text = sectionEmpMsg.SendUser.UserName;
        this.sendUserLoginName = sectionEmpMsg.SendUser.UserName;
        this.txtMsgContent.Text = sectionEmpMsg.MsgContent;
        ViewState["sendUserLoginName"] = this.sendUserLoginName;
    }

    protected void Button1_Click(object sender, EventArgs e) {
        this.txtMsgContent.Visible = false;
        this.txtSendMsg.Visible = true;
        this.Button1.Enabled = false;
        this.btnSendMsg.Enabled = true;
    }

    protected void btnSendMsg_Click(object sender, EventArgs e) {
        if(ViewState["sendUserLoginName"] != null)
        {
            this.sendUserLoginName = (string) ViewState["sendUserLoginName"];
        }
        SectionEmpMsgtbService sectionEmpMsgtbService = new SectionEmpMsgtbService();
        User curLoginUser = (User) Session["user"];
        int msgid = sectionEmpMsgtbService.saveSectionEmpMsg(this.sendUserLoginName, curLoginUser.LoginName, this.txtSendMsg.Text, DateTime.Now);
        MessageAwoke.Instance().AddToShortMsg(this.sendUserLoginName, msgid);
    }
   
}
